();
11
function rollback ();
12
}
Connect is the connection to the database, execute is to execute a SQL, if this SQL is a query, then getallbyobject represents the result of the query returned through the object, Getallbyassocarray represents the result in the associative array returned, Getallbyarray represents the return of the result in an ordinary array, the BeginTrans represents the opening of a transaction, that is, opening
not so ideal. To address this problem, we naturally think of extracting this part of implementation into a base class. We did. For example, here we define a modelbase type
Using System. componentmodel;Using System. diagnostics; Namespace Wpfmvvmsample. Models { Public Abstract Class Modelbase: inotifypropertychanged { Public Event Propertychangedeventhandler propertychanged; Protected Void Onprop
I have always felt that simplicity is also a kind of beauty, so is the architecture, and so is the case for human beings.
For ease of understanding, the source code is released here: Click here to download
We strongly recommend that you read this article with the Code. After all, code is the best way for programmers to communicate.
Previous articles analyzed the system and drew a sketch of the architecture. For details, see "step by step (analysis)".
The implementation of the
example is based on Enterprise Library 5.0.
Let's take a look at the example below. Suppose we have another model type called order, which indicates order. We hope that its code will be as concise as below.
using system; namespace wpfmvvmsample. models { Public class order: modelbase { Public int orderid {Get; set ;} Public datetime orderdate {Get; Set ;}}
[Note] Here we only inherit modelba
Laravel supports multiple models of relation, corresponding to One2One, one2many,many2many,hasmanythrough,polymorphic, many2many polymorphic relationships between models.Heart1. All relation are defined by the method on the model class;2. Relationship and model itself are based on query Builder, so the operation of relation can also use a method similar to query Builder, such as: can support cascading;3.Dynamic property of Model: This is the result of the Model->relation method reference, which
example:
1. Create a WinForm program and reference ZhCun. Framework. Common and ZhCunFramework. DataAccess
2. Create the Models folder and create Test1.cs and Test2.cs respectively. The two are table ing:
namespace ZhCun.Framework.WinTest.Models{ public class Test1 : ModelBase { [ModelAttribute(IsPrimaryKey = true, IsIdentity = true)] public int Id { set; get; } public string Name { set; get; } public string Age { s
It's just a framework. For more information about activerecord development, see terrylee's castle development article. During the development framework encapsulation, we encountered the problem of ignoring the calling of different business objects for simplified consideration. Therefore, we have added uibase with a generic parameter, however, this makes it much more complicated. I want to hear your opinions!
Using system;
Using system. Collections. Generic;
Using system. text;
Namespace console
can customize a function such as MyError ($ code). In this function, I will beautify my output and decide whether to exit/die.
If exception handling is used, do I have to add try/catch to all possible errors? Isn't there a bunch of try/catch... in a piece of my program? what is the difference between me directly using die/exit or calling custom MyError? If the Exception can be passed up, I should handle it immediately, for example, the database cannot be connected, or the file does not exist w
take a step-by-step practice it;
Second, "Dynamic" support new table, plan ahead
First we create the Modelbase class library, which holds some interfaces and base classes related to the entity, as shown in the diagram:
According to the project structure, I need to explain the meaning of each file;
IEntity interface and Abstractentitybase class, as the name suggests, you should guess that they are the entity base class, why to define it, is mainly c
EntityFrameWork one-to-multiple relationship processing, entityframework
Scenario 1: one Article Category contains multiple articles, and one Article can only correspond to one Category.
The code for Article and Category is as follows:
///
Public class Category: ModelBase {// Category Name public string Name {get; set;} // many Articles in a certain Category are included in public ICollection
The following is a key step. In OnModelCreating of En
has successfully generated the Android binding library. Next, create an Android project and try it out.
7. Add and reference the Android-bound library just now, and then modify the MainActivity. cs code.
Using Android. app; using Android. widget; using Android. OS; using Com. tencent. MM. opensdk. openapi; using Com. tencent. MM. opensdk. modelbase; using Com. tencent. MM. opensdk. modelmsg; using System; using Android. graphics; using System. IO;
abstract a base class for data access and write several methods for overloading in actual use to facilitate calls./// Implement MyUserDAL, inherit from DALBase
public class MyUserDAL : DALBase
Question 2: Table association. In this case, we need to think of a dictionary. The dictionary is really hard to emphasize. For the UI Layer, we extract data from the model. Therefore, the associated data must also be in the model. We create a base class for the model that requires the associated data, as
attribute. The orm I wrote is lightweight and only a few key attributes are involved,
The Code is as follows:
Public class modelattribute: attribute {// View code
The following is an example of the usage feature of an object class. It specifies that the column name of the ID is "ID". It cannot be empty. It is self-incrementing and is the primary key:
public class Test1 : ModelBase { [ModelAttribute(IsPrimaryKey = true, IsIdentity = true, I
implementation method is described in the video of Channel 9. The implementation method is as follows:
public class ModelBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected bool SetProperty
The calling method is further simplified:
private string name; public string Name { get { return name; } set { this.SetProperty(ref this.name, value)
has successfully generated the Android binding library. Next, create an Android project and try it out.
7. Add and reference the Android-bound library just now, and then modify the MainActivity. cs code.
Using Android. app; using Android. widget; using Android. OS; using Com. tencent. MM. opensdk. openapi; using Com. tencent. MM. opensdk. modelbase; using Com. tencent. MM. opensdk. modelmsg; using System; using Android. graphics; using System. IO;
easier for others to read the code we write, and to help us recall the intent to write this code when we have written the code for a long time and then review it. After all, after writing tens of thousands of lines of code for a long time, it is normal to forget the intention of writing this code.The symbols commonly used for annotations in Python are # and ' ', #号一般用于注释单行代码写在要注释的代码最左边, and three-line annotations are generally used to interpret blocks of code, such as# while True:# Msg=inpu
count = 60; Once defined as a constant, the change will be an error.User InteractionName = input ("What is Your Name:")Print ("Hello" + name)After executing the script, the Discovery program will wait for the name to go down.Let the user enter multiple information:Name = input ("What is Your Name:")Age = Input ("What old is You:")Hometown = input ("Where is your Hometown:")Print ("Hello", Name, "Your is", age, "years old, you came from", hometown)Execution output:What is your Name:wu QianqianHo
Instancetypes class in models and adds a new record to the instance by Instance_type_ref.update (values) (update is provided by this class of Novabase, Very convenient). The record is then stored in the datasheet via Instance_type_ref.save () (save is also provided by the class Novabase). You can refer to this class in nova.openstack.common.db.sqlalchemy.models.py modelbase.
To create a summary of methods:
1. Need to pass in context and values (thi
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.